Loading data
library(jsonlite)
## Warning: package 'jsonlite' was built under R version 3.3.3
data <- fromJSON("https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_month.geojson", flatten=TRUE)
features = data$features
features$type= NULL
features$properties.url=NULL
features$properties.detail= NULL
features$geometry.type= NULL
creating nearest locations of epicenters of earthquakes.
features$lon=NULL
for (i in 1:nrow(features)){
features$lon[i]=floor(features$geometry.coordinates[[i]][1])}
features$lat=NULL
for (i in 1:nrow(features)){
features$lat[i]=floor(features$geometry.coordinates[[i]][2])}
features$depth=NULL
for (i in 1:nrow(features)){
features$depth[i]=features$geometry.coordinates[[i]][3]}
showing those locations on map
library(rworldmap)
## Warning: package 'rworldmap' was built under R version 3.3.3
## Loading required package: sp
## Warning: package 'sp' was built under R version 3.3.3
## ### Welcome to rworldmap ###
## For a short introduction type : vignette('rworldmap')
newmap <- getMap(resolution = "low")
plot(newmap, xlim = c(-90, 90), ylim = c(-180, 180), asp = 1)
points(features$lon, features$lat, cex=0.6, col= "red")
Counting earthquakes according to the locations and plotting
library(plyr)
## Warning: package 'plyr' was built under R version 3.3.3
earthquakes <- ddply(features, .(lat, lon), "nrow")
names(earthquakes)[3] = "number"
library(ggmap)
## Warning: package 'ggmap' was built under R version 3.3.3
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.3.3
map <- get_map(location = "Europe",zoom= 4)
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=Europe&zoom=4&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Europe&sensor=false
points = ggmap(map) +geom_point(aes(x = lon, y = lat,size=number),data=earthquakes)
points
## Warning: Removed 260 rows containing missing values (geom_point).
map <- get_map(location = "NorthAmerica",zoom = 4)
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=NorthAmerica&zoom=4&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=NorthAmerica&sensor=false
points = ggmap(map) +geom_point(aes(x = lon, y = lat,size=number),data=earthquakes)
points
## Warning: Removed 261 rows containing missing values (geom_point).
map <- get_map(location = "Asia",zoom= 4)
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=Asia&zoom=4&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Asia&sensor=false
points = ggmap(map) +geom_point(aes(x = lon, y = lat,size=number),data=earthquakes)
points
## Warning: Removed 245 rows containing missing values (geom_point).
map <- get_map(location = "Australia",zoom = 4)
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=Australia&zoom=4&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Australia&sensor=false
points = ggmap(map) +geom_point(aes(x = lon, y = lat,size=number),data=earthquakes)
points
## Warning: Removed 220 rows containing missing values (geom_point).
map <- get_map(location = "Africa",zoom= 4)
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=Africa&zoom=4&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Africa&sensor=false
points = ggmap(map) +geom_point(aes(x = lon, y = lat,size=number),data=earthquakes)
points
## Warning: Removed 260 rows containing missing values (geom_point).
map <- get_map(location = "SouthAmerica",zoom = 4)
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=SouthAmerica&zoom=4&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=SouthAmerica&sensor=false
points = ggmap(map) +geom_point(aes(x = lon, y = lat,size=number),data=earthquakes)
points
## Warning: Removed 243 rows containing missing values (geom_point).
map <- get_map(location = "Antartica",zoom = 4)
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=Antartica&zoom=4&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Antartica&sensor=false
points = ggmap(map) +geom_point(aes(x = lon, y = lat,size=number),data=earthquakes)
points
## Warning: Removed 265 rows containing missing values (geom_point).